import java.util.ArrayList;
import java.util.List;

/**
 * Created whit IntelliJ IDEA.
 * Description：
 * User：ZHONGCHEN
 * Date:2022-04-18
 * Time:23:26
 */
public class TestDemo {
//    386. 字典序排数
//    输入：n = 13
//    输出：[1,10,11,12,13,2,3,4,5,6,7,8,9]
    class Solution {
        List<Integer> ans = new ArrayList<>();
        public List<Integer> lexicalOrder(int n) {
            for (int i = 1; i <= 9; i++) {
                dfs(i, n);
            }
            return ans;
        }
        void dfs(int cur, int limit) {
            if (cur > limit){
                return ;
            }
            ans.add(cur);
            for (int i = 0; i <= 9; i++){
                dfs(cur * 10 + i, limit);
            }
        }
    }

}

